package com.accessibleworlds.util;

import java.util.Locale;

import android.content.Context;
import android.speech.tts.TextToSpeech;

public class TextToSpeechesPico extends TextToSpeeches{
	
	TextToSpeech tts = null;

	boolean initialized = false;
	
	@Override
	public void speak(Context context,final String data) {
		initialized = false;
		tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
			public void onInit(int status) {
				initialized = true;
				if (status == TextToSpeech.SUCCESS){
					tts.setLanguage(Locale.US);
					tts.speak(data, TextToSpeech.QUEUE_FLUSH, null);
				}
			}
		});
	}

	@Override
	public void close() {
		tts.shutdown();
	}

	@Override
	public void stopSpeaking(){
		if(tts != null)
			tts.stop();
	}

	public boolean isSpeakingNow(){
		while(!initialized);
		if(tts != null)
			return tts.isSpeaking();
		else
			return false;
	}
}
